package tmts.commands;

import java.io.File;

import tmts.Server;
import tmts.SkaterParser;

public class Add extends Command
{

    public Add(Server server)
    {
        super(server);
    }

    @Override
    public String getActionString()
    {
        return "add";
    }

    @Override
    public String execute(String[] command)
    {
        if (command.length != 2)
        {
            return "Command not formed properly. The format has to be 'Add <skaterfile>'";
        }
        else
        {
            if(!command[1].endsWith(".csv"))
            {
                command[1] += ".csv";
            }
            
            File skaterFile = new File("skaters/" + command[1]);
            if (skaterFile.exists())
            {
                this.server.addSkater(SkaterParser.parseFile(skaterFile));
                return "Skater added from file: " + command[1];
            } else
            {
                return "File doesn't exists";
            }
        }
    }

}
